package c.a.a.e0;

import android.animation.Animator.AnimatorListener;
import android.graphics.PointF;
import android.view.Choreographer;
import android.view.Choreographer.FrameCallback;
import c.a.a.c;
import c.a.a.f;

/* compiled from: LottieValueAnimator */
public class d extends a implements FrameCallback {
    public float c = 1.0f;
    public boolean d = false;
    public long e = 0;
    public float f = 0.0f;
    public int g = 0;
    public float h = -2.14748365E9f;
    public float i = 2.14748365E9f;
    public f j;
    public boolean k = false;

    public void c() {
        i();
        a(g());
    }

    public void cancel() {
        for (AnimatorListener onAnimationCancel : this.b) {
            onAnimationCancel.onAnimationCancel(this);
        }
        i();
    }

    public float d() {
        f fVar = this.j;
        if (fVar == null) {
            return 0.0f;
        }
        float f = this.f;
        float f2 = fVar.k;
        return (f - f2) / (fVar.l - f2);
    }

    public void doFrame(long j) {
        h();
        f fVar = this.j;
        if (fVar != null && this.k) {
            long j2 = this.e;
            long j3 = 0;
            if (j2 != 0) {
                j3 = j - j2;
            }
            float abs = ((float) j3) / ((1.0E9f / fVar.m) / Math.abs(this.c));
            float f = this.f;
            if (g()) {
                abs = -abs;
            }
            f += abs;
            this.f = f;
            abs = f();
            float e = e();
            PointF pointF = f.a;
            int i = (f < abs || f > e) ? 0 : 1;
            i ^= 1;
            this.f = f.b(this.f, f(), e());
            this.e = j;
            b();
            if (i != 0) {
                if (getRepeatCount() == -1 || this.g < getRepeatCount()) {
                    for (AnimatorListener onAnimationRepeat : this.b) {
                        onAnimationRepeat.onAnimationRepeat(this);
                    }
                    this.g++;
                    if (getRepeatMode() == 2) {
                        this.d ^= 1;
                        this.c = -this.c;
                    } else {
                        this.f = g() ? e() : f();
                    }
                    this.e = j;
                } else {
                    this.f = this.c < 0.0f ? f() : e();
                    i();
                    a(g());
                }
            }
            if (this.j != null) {
                float f2 = this.f;
                if (f2 < this.h || f2 > this.i) {
                    throw new IllegalStateException(String.format("Frame must be [%f,%f]. It is %f", new Object[]{Float.valueOf(this.h), Float.valueOf(this.i), Float.valueOf(this.f)}));
                }
            }
            c.a("LottieValueAnimator#doFrame");
        }
    }

    public float e() {
        f fVar = this.j;
        if (fVar == null) {
            return 0.0f;
        }
        float f = this.i;
        if (f == 2.14748365E9f) {
            f = fVar.l;
        }
        return f;
    }

    public float f() {
        f fVar = this.j;
        if (fVar == null) {
            return 0.0f;
        }
        float f = this.h;
        if (f == -2.14748365E9f) {
            f = fVar.k;
        }
        return f;
    }

    public final boolean g() {
        return this.c < 0.0f;
    }

    public float getAnimatedFraction() {
        if (this.j == null) {
            return 0.0f;
        }
        float e;
        float e2;
        float f;
        if (g()) {
            e = e() - this.f;
            e2 = e();
            f = f();
        } else {
            e = this.f - f();
            e2 = e();
            f = f();
        }
        return e / (e2 - f);
    }

    public Object getAnimatedValue() {
        return Float.valueOf(d());
    }

    public long getDuration() {
        f fVar = this.j;
        return fVar == null ? 0 : (long) fVar.b();
    }

    public void h() {
        if (this.k) {
            Choreographer.getInstance().removeFrameCallback(this);
            Choreographer.getInstance().postFrameCallback(this);
        }
    }

    public void i() {
        Choreographer.getInstance().removeFrameCallback(this);
        this.k = false;
    }

    public boolean isRunning() {
        return this.k;
    }

    public void j(float f) {
        if (this.f != f) {
            this.f = f.b(f, f(), e());
            this.e = 0;
            b();
        }
    }

    public void k(float f, float f2) {
        if (f <= f2) {
            float f3;
            float f4;
            f fVar = this.j;
            if (fVar == null) {
                f3 = -3.4028235E38f;
            } else {
                f3 = fVar.k;
            }
            if (fVar == null) {
                f4 = Float.MAX_VALUE;
            } else {
                f4 = fVar.l;
            }
            this.h = f.b(f, f3, f4);
            this.i = f.b(f2, f3, f4);
            j((float) ((int) f.b(this.f, f, f2)));
            return;
        }
        throw new IllegalArgumentException(String.format("minFrame (%s) must be <= maxFrame (%s)", new Object[]{Float.valueOf(f), Float.valueOf(f2)}));
    }

    public void setRepeatMode(int i) {
        super.setRepeatMode(i);
        if (i != 2 && this.d) {
            this.d = false;
            this.c = -this.c;
        }
    }
}
